package nil.ed.simulator.request.ui.jfx.application;

import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
import nil.ed.simulator.request.guice.GuiceManager;
import nil.ed.simulator.request.ui.jfx.manager.FxManager;

import java.io.Closeable;
import java.io.IOException;
import java.util.Objects;


@Slf4j
public class Main extends Application {
	@Override
	public void start(Stage stage) throws Exception {
		log.info("OK");
		stage.setOnCloseRequest(e -> {
			GuiceManager.INJECTOR.getAllBindings().forEach((key, value) -> {
				Object obj = value.getProvider().get();
				if (obj instanceof Closeable) {
					try {
						((Closeable) obj).close();
					} catch (IOException ioException) {
						ioException.printStackTrace();
					}
				}
			});
			System.exit(0);
		});
		stage.setTitle("packetRobber-delin_OneZero");
		stage.setWidth(1500);
		stage.setHeight(1000);
		stage.setResizable(false);
		stage.getIcons().add(new Image(
				Objects.requireNonNull(Main.class.getResourceAsStream("/ui/source/doge.jpg"))));
		FxManager.setStage(stage);
		FxManager.gotoMain();
		stage.show();
	}

	public static void main(String...args) {
		launch(args);
	}
}
